/*
** move_player.c for move_player in /home/Smaxo/zappy-2015-2014s-renard_g/serv-src
**
** Made by maximilien addari
** Login   <addari_m@epitech.net>
**
** Started on  Fri Jun  8 11:15:39 2012 maximilien addari
** Last update Thu Jul 19 17:56:42 2012 pierrick druart
*/

#include			<unistd.h>
#include			<stdlib.h>
#include			<stdio.h>

#include			"server.h"

static void			move_up(t_game *, t_gamer *);
static void			move_right(t_game *, t_gamer *);
static void			move_down(t_game *, t_gamer *);
static void			move_left(t_game *, t_gamer *);

static const t_func_mov		func_mov[] =
{
  { &move_up },
  { &move_right },
  { &move_down },
  { &move_left },
};

static void			move_right(t_game *game, t_gamer *gamer)
{
  if ((gamer->coord).x == ((game->coord).x - 1))
    (gamer->coord).x = 0;
  else
    (gamer->coord).x += 1;
}

static void			move_left(t_game *game, t_gamer *gamer)
{
  if ((gamer->coord).x == 0)
    (gamer->coord).x = (game->coord).x - 1;
  else
    (gamer->coord).x -= 1;
}

static void			move_down(t_game *game, t_gamer *gamer)
{
  if ((gamer->coord).y == ((game->coord).y - 1))
    (gamer->coord).y = 0;
  else
    (gamer->coord).y += 1;
}

static void			move_up(t_game *game, t_gamer *gamer)
{
  if ((gamer->coord).y == 0)
    (gamer->coord).y = (game->coord).y - 1;
  else
    (gamer->coord).y -= 1;
}

void				move_player(t_game *game, t_gamer *gamer,
    unsigned char direction)
{
  func_mov[direction - 1].f(game, gamer);
}
